package com.czh.gzskzn.qqkonjian.Activity;


import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.czh.gzskzn.qqkonjian.DaKaFagment.DakaFragment;
import com.czh.gzskzn.qqkonjian.DaKaFagment.TonJiFragment;
import com.czh.gzskzn.qqkonjian.Fragment.FragmentXiaoXi;
import com.czh.gzskzn.qqkonjian.R;

/**
 * Created by gzsk on 2017/5/9.
 * name  陈忠红
 * email czhhx15599109256@163.com
 */

public class DakaActivity extends AppCompatActivity implements View.OnClickListener{

    private LinearLayout daKa,tonJi;
    private TextView tvDaKa,tvTonJi;
    private ImageView imDaKa,imTonJi;

//    页面
    private DakaFragment daKaFragemnt;
    private TonJiFragment tonJiFragment;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.daka_activity);
          intiView();
    }

    private void clickerDaKa() {

        // 实例化Fragment页面
        daKaFragemnt = new DakaFragment();
        // 得到Fragment事务管理器
        FragmentTransaction fragmentTransaction = this
                .getSupportFragmentManager().beginTransaction();
        // 替换当前的页面
        fragmentTransaction.replace(R.id.frame_daka_content, daKaFragemnt);
        // 事务管理提交
        fragmentTransaction.commit();
        imDaKa.setImageResource(R.drawable.daka1);
        tvDaKa.setTextColor(Color.parseColor("#FF0C97FF"));

        // 改变选中状态
        tvDaKa.setSelected(true);
        imDaKa.setSelected(true);
        imTonJi.setSelected(false);
        tvDaKa.setSelected(false);
    }
    private void clickerTonJi() {

        // 实例化Fragment页面
        tonJiFragment = new TonJiFragment();
        // 得到Fragment事务管理器
        FragmentTransaction fragmentTransaction = this
                .getSupportFragmentManager().beginTransaction();
        // 替换当前的页面
        fragmentTransaction.replace(R.id.frame_daka_content, tonJiFragment);
        // 事务管理提交
        fragmentTransaction.commit();
        // 改变选中状态
        tvDaKa.setSelected(false);
        imDaKa.setSelected(false);
        imTonJi.setSelected(true);
        tvDaKa.setSelected(true);
    }

    private void intiView() {

        daKa = (LinearLayout) findViewById(R.id.ll_dakai);
        tonJi = (LinearLayout) findViewById(R.id.ll_daka_tonji);
        tvDaKa = (TextView) findViewById(R.id.tv_daka_daka);
        tvTonJi = (TextView) findViewById(R.id.tv_daka_tonji);
        imDaKa = (ImageView) findViewById(R.id.image_daka);
        imTonJi = (ImageView) findViewById(R.id.image_daka_tonji);
        clickerDaKa();
        imDaKa.setOnClickListener(this);
        imTonJi.setOnClickListener(this);
        tvTonJi.setOnClickListener(this);
        tvDaKa.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch(v.getId()){
            case R.id.image_daka:
//               打卡
                clearSelection();
                clickerDaKa();
                imDaKa.setImageResource(R.drawable.daka1);
                tvDaKa.setTextColor(Color.parseColor("#FF0C97FF"));
                break;
            case R.id.image_daka_tonji:
//                统计
                clearSelection();
                clickerTonJi();
                imTonJi.setImageResource(R.drawable.tongji1);
                tvTonJi.setTextColor(Color.parseColor("#FF0C97FF"));
                break;
            case R.id.tv_daka_daka:
                clearSelection();
                clickerDaKa();
                imDaKa.setImageResource(R.drawable.daka1);
                tvDaKa.setTextColor(Color.parseColor("#FF0C97FF"));
                break;
            case R.id.tv_daka_tonji:
                clearSelection();
                clickerDaKa();
                imTonJi.setImageResource(R.drawable.tongji1);
                tvTonJi.setTextColor(Color.parseColor("#FF0C97FF"));
                break;

        }
    }

    private void clearSelection() {
        imDaKa.setImageResource(R.drawable.daka2);
        tvDaKa .setTextColor(Color.parseColor("#82858b"));
        imTonJi.setImageResource(R.drawable.tongji2);
        tvTonJi.setTextColor(Color.parseColor("#82858b"));

    }
}